import { reactive, watch, ref, onMounted } from 'vue';
import calendar from '@utils/calendar';

export default function importConfig() {
  const day = new Date('2023-11-27');
  const specificTime = ref(new Date('2023-11-27'));
  const base = reactive({
    time: null,
    holidayList: ['2023-11-27'],
    editVisible: false,
    form: { date: '', work: 'work' },
  });
  // 农历节日
  const isFestival = (year, month, date) => {
    const lunarDay = calendar.solar2lunar(year, month, date);

    // 公历节日\农历节日\农历节气
    let festAndTerm = [];
    festAndTerm.push(lunarDay.festival == null ? '' : ' ' + lunarDay.festival);
    festAndTerm.push(lunarDay.lunarFestival == null ? '' : '' + lunarDay.lunarFestival);
    festAndTerm.push(lunarDay.Term == null ? '' : '' + lunarDay.Term);
    festAndTerm = festAndTerm.join('');

    return festAndTerm != '';
  };
  //日期对应农历
  const solarDate2lunar = (year, month, date) => {
    const lunar = calendar.solar2lunar(year, month, date);

    const lunarMD = lunar.IMonthCn + lunar.IDayCn;
    // 公历节日\农历节日\农历节气
    let festAndTerm = [];
    festAndTerm.push(lunar.festival == null ? '' : ' ' + lunar.festival);
    festAndTerm.push(lunar.lunarFestival == null ? '' : '' + lunar.lunarFestival);
    festAndTerm.push(lunar.Term == null ? '' : '' + lunar.Term);
    festAndTerm = festAndTerm.join('');

    return festAndTerm == '' ? lunarMD : festAndTerm;
  };

  const init = () => {};
  //获取当前点击日期
  const getDate = (year, month, date) => {
    const str = year + '-' + month + '-' + date;
    specificTime.value = new Date(str);
    // base.specificTime.setMonth(month-1);
    // base.specificTime.setDate(1);
  };
  //右键出现选择班或修的弹窗
  const onRightClick = (year, month, date) => {
    base.form.date = year + '-' + month + '-' + date;
    if (!base.editVisible) {
      base.editVisible = true;
    }
  };
  //弹窗确认
  const handleOk = () => {};
  //弹窗取消
  const handleCancel = () => {
    base.editVisible = false;
  };

  const getddd = () => {
    // console.log('测试数据');
  };

  watch(
    () => specificTime.value,
    (res) => {
      // specificTime.value.setMonth(1);
    },
  );

  return {
    base,
    specificTime,
    init,
    isFestival,
    solarDate2lunar,
    getDate,
    onRightClick,
    handleOk,
    handleCancel,
    getddd,
  };
}
